#!/usr/bin/env python
#_*_coding:utf-8_*_
'''
 * Created on 2016/10/16 21:31.
 * @author: Chinge_Yang.
'''

import menu

while True:
    #定义一层菜单为字典
    one_dict = {}
    #获取字典所有的键
    one_layer = menu.menu.keys()
    #获取字典所有的枚举
    one_enu = enumerate(one_layer)
    #一层菜单字典
    for index1,value1 in one_enu:
        one_dict[index1]=value1

    for k1 in one_dict:
        print ("\033[32m%d\033[0m --> %s" %(k1,one_dict[k1]))
    print ("输入【back】：返回；【quit】：退出")

    once_select = input("请输入你的选择:\n").strip()
    if once_select.isdigit():
        once_select = int(once_select)
        if 0 <= once_select < len(one_dict):
            print("---->进入一级菜单 \033[32m%s\033[0m" %(one_dict[once_select]))
            while True:
                #定义二层菜单为字典
                two_dict = {}
                # 获取字典所有的键
                two_layer = menu.menu[one_dict[once_select]].keys()
                # 获取字典所有的枚举
                two_enu = enumerate(two_layer)
                # 二层菜单字典
                for index2, value2 in two_enu:
                    two_dict[index2] = value2
                # 打印二层菜单
                for k2 in two_dict:
                    print("\033[32m%d\033[0m --> %s" % (k2, two_dict[k2]))
                print("输入【back】：返回；【quit】：退出")

                twice_select = input("请输入你的选择:\n").strip()
                if twice_select.isdigit():
                    twice_select = int(twice_select)
                    if 0 <= twice_select < len(two_dict):
                        print("---->进入二级菜单 \033[32m%s\033[0m" % (two_dict[twice_select]))
                        # 定义三层菜单列表
                        three_layer = menu.menu[one_dict[once_select]][two_dict[twice_select]]
                        while True:
                            # 打印三层菜单
                            for k3 in three_layer:
                                print (k3)
                            print ("输入【back】：返回；【quit】：退出")
                            three_select = input("请输入你的选择:\n").strip()
                            if three_select == "back":
                                break
                            elif three_select == "quit":
                                exit ("----谢谢使用----")
                            continue

                else:
                    if twice_select == "back":
                        break
                    elif twice_select == "quit":
                        exit ("----谢谢使用----")
                    print ("\033[31m请输入数字\033[0m")
        else:
            print("----\033[31m数字超出范围，请重新输入！\033[0m----")
    else:
        if once_select == "back":
            break
        elif once_select == "quit":
            exit("----谢谢使用----")
        print ("\033[31m请输入数字\033[0m")
